package graphs

import (
	"power/core/dao/table"
	"power/core/dao/graphdao"
	"power/core/localwrap"
)

var logProjects = localwrap.GetLogger().Fork("power/core/service/graphs", "Projects")

type Projects struct{}

func (s Projects) Query(param graphdao.ProjectsQueryParam) ([]table.Project, int64) {
	logProjects.Debug().Func("Query").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.Projects{RedisedMysql: d}.Query(param)
}

func (s Projects) Get(id int) table.Project {
	logProjects.Debug().Func("Get").Int("id", id).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.Projects{RedisedMysql: d}.Get(id)
}

func (s Projects) Add(param graphdao.ProjectsAddParam) table.Project {
	logProjects.Debug().Func("Add").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.Projects{RedisedMysql: d}.Add(param)
}

func (s Projects) Update(param graphdao.ProjectsUpdateParam) {
	logProjects.Debug().Func("Update").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	graphdao.Projects{RedisedMysql: d}.Update(param)
}

func (s Projects) Delete(id int) {
	logProjects.Debug().Func("Delete").Int("id", id).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	graphdao.Projects{RedisedMysql: d}.Delete(id)
}

//ListByGraphId
func (s Projects) ListByGraphId(graphId int) []table.Project {
	logProjects.Debug().Func("ListByGraphId").Int("graphId", graphId).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.Projects{RedisedMysql: d}.ListByGraphId(graphId)
}

//ListByUid
func (s Projects) ListByUid(uid int) []table.Project {
	logProjects.Debug().Func("ListByUid").Int("uid", uid).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return graphdao.Projects{RedisedMysql: d}.ListByUid(uid)
}
